const { ccclass, property } = cc._decorator;

import i from "./EventMgr"
import r from "./MatchGameEventType"
import n from "./frameworkManager"
import l from "./EngineUtil"
import s from "./TimeUtils"
import c from "./ObstacleAniCtrl"
import u from "./TargetAniCtrl"
import p from "./EmptyObstacleItemCtrl"
import d from "./MultiObstaclePrefabCtrl"
import h from "./ObstaclePrefabCtrl"
import f from "./MatchGameCenterCtrl"
import g from "./MatchGameViewCtrl"
import y from "./MatchGameData"
import m from "./MatchGameConfig"
import _, { LayerType, ObstacleAllType, ObstacleAllType1, SpecifyColor } from "./ObstacleConfig"
import v from "./MatchGameAudioMgr"
import b from "./MatchGameDataMgr"
import C from "./MatchItemCtrl";

@ccclass
 class ObstacleCtrl {
    static MagicTouchTotalCount = 3;
    static TOTAL_OBSTCLE_COUNT = 23;

    public obstacleItemPool = new cc.NodePool("obstacleItemPool");
    public obstacleItem = null;
    public emptyObstaclePool = new cc.NodePool("emptyObstaclePool");
    public emptyObstacleItem = null;
    public multiObstaclePool = new cc.NodePool("multiObstaclePool");
    public multiObstacleItem = null;
    public lowestParent = null;
    public middleParents = null;
    public topParents = null;
    public multiAreaParent = null;
    public allObstacleClearArr = [];
    public isReady = false;
    public totalGemCount = -1;
    public matchGemCount = -1;
    public createGemCount = -1;

    constructor() {
        this.obstacleItemPool = new cc.NodePool("obstacleItemPool");
        this.obstacleItem = null;
        this.emptyObstaclePool = new cc.NodePool("emptyObstaclePool");
        this.emptyObstacleItem = null;
        this.multiObstaclePool = new cc.NodePool("multiObstaclePool");
        this.multiObstacleItem = null;
        this.lowestParent = null;
        this.middleParents = null;
        this.topParents = null;
        this.multiAreaParent = null;
        this.allObstacleClearArr = [];
        this.isReady = false;
        this.totalGemCount = -1;
        this.matchGemCount = -1;
        this.createGemCount = -1;
    }

    static _instance;
    static getInstance():ObstacleCtrl {
        this._instance || (this._instance = new ObstacleCtrl());
        return this._instance;
    };
    public ready(e, t, a, o, i, r) {
        this.obstacleItem = e;
        this.emptyObstacleItem = t;
        this.lowestParent = a || null;
        this.middleParents = o || null;
        this.topParents = i || null;
        this.allObstacleClearArr = [];
        if (f) {
            this.multiAreaParent = f._instance.multiAreaParent;
            this.multiAreaParent && this.multiAreaParent.removeAllChildren();
            this.multiObstacleItem = f._instance.multiObstacleItem;
        } else this.multiObstacleItem = r;
        this.isReady = true;
    };
    public init(e) {
        this.initObstacleClearArr();
        this.initTarget(e.targetMatchData);
        this.setAllHoneys();
    };
    public initTarget(e) {
        for (var t = y.getSquareNumberType(m.SquareType.MatchItem), a = 0; a < e.length; a++) e[a].squareType == t && e[a].itemType == m.MatchItemType.purpleGem && this.initGemCount(e[a].tootalCount);
    };
    public initObstacleClearArr() {
        this.allObstacleClearArr = [];
        for (var e = 0; e < 23; e++) this.allObstacleClearArr.push({
            obstacleType: e + 1,
            count: 0
        });
    };
    public pushObstacleClearArr(e, t?) {
        void 0 === t && (t = 1);
        for (var a = 0; a < this.allObstacleClearArr.length; a++) this.allObstacleClearArr[a].obstacleType == e && (this.allObstacleClearArr[a].count += t);
    };
    public createObstacleItem(e, t, a, o, i?) {
        void 0 === i && (i = null);
        if (i || this.getPosIsEnmpty(e, t, o)) {
            var r, l = a.split("_"), s = l[0], c = null;
            if (Number(s) ==ObstacleAllType.WoodenBox) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: Number(l[1]),
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.WoodenBox,
                    name:ObstacleAllType1.WBX,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.ColorBox) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: Number(l[2]),
                    Hp: Number(l[1]),
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.ColorBox,
                    name:ObstacleAllType1.CBX,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Grass) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: Number(l[1]),
                    LayoutType:LayerType.Lowest,
                    ObstacleAllType:ObstacleAllType.Grass,
                    name:ObstacleAllType1.GRA,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Egg) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Egg,
                    name:ObstacleAllType1.EGG,
                    aroundMatch: true,
                    createOther: false,
                    canMove: true
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Vase) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 2,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Vase,
                    name:ObstacleAllType1.VAS,
                    aroundMatch: true,
                    createOther: false,
                    canMove: true
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Honey) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 1,
                    LayoutType:LayerType.Top,
                    ObstacleAllType:ObstacleAllType.Honey,
                    name:ObstacleAllType1.HOY,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Oyster) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 3,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Oyster,
                    name:ObstacleAllType1.OYS,
                    aroundMatch: true,
                    createOther: false,
                    canMove: true
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Flowerpot) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 2,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Flowerpot,
                    name:ObstacleAllType1.FLP,
                    aroundMatch: true,
                    createOther: true,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Stone) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.null,
                    Hp: Number(l[1]),
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Stone,
                    name:ObstacleAllType1.STO,
                    aroundMatch: false,
                    createOther: true,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.PorcelainPig) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.null,
                    Hp: 1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.PorcelainPig,
                    name:ObstacleAllType1.PPG,
                    aroundMatch: false,
                    createOther: false,
                    canMove: true
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.MailBox) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.MailBox,
                    name:ObstacleAllType1.MAI,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Bird) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Bird,
                    name:ObstacleAllType1.BID,
                    aroundMatch: false,
                    createOther: false,
                    canMove: true
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.GoldCoin) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.GoldCoin,
                    name:ObstacleAllType1.GCN,
                    aroundMatch: true,
                    createOther: false,
                    canMove: true
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.PurpleFlower) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 1,
                    LayoutType:LayerType.Lowest,
                    ObstacleAllType:ObstacleAllType.PurpleFlower,
                    name:ObstacleAllType1.PFL,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.MagicHat) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.MagicHat,
                    name:ObstacleAllType1.MHT,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.Rock) {
                c = {
                    enable: true,
                    MoveStatus: true,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 2,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Rock,
                    name:ObstacleAllType1.RCK,
                    aroundMatch: false,
                    createOther: false,
                    canMove: true
                };
                return this.createSingleObstacleItem(e, t, c, i);
            }
            if (Number(s) ==ObstacleAllType.GrassLand) {
                n.log("创建草丛-----", s, l);
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 2,
                        height: 2
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 5,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.GrassLand,
                    name:ObstacleAllType1.GLD,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                r = this.createMultiObstacleItem(e, t, c, i);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType: c.LayoutType,
                    ObstacleAllType:ObstacleAllType.GrassLand,
                    name:ObstacleAllType1.GLD,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyObstacleItems(e, t, r, u);
                return r;
            }
            if (Number(s) ==ObstacleAllType.ColorBottle) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 2,
                        height: 2
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 4,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.ColorBottle,
                    name:ObstacleAllType1.CBO,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                r = this.createMultiObstacleItem(e, t, c, i);
                if (i) {
                    r.initBottleInfo(l[1], !!i);
                    return r;
                }
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType: c.LayoutType,
                    ObstacleAllType:ObstacleAllType.OneBottle,
                    name:ObstacleAllType1.OBO,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyObstacleItems(e, t, r, u);
                n.log("obsItem---", r.emptyObstacleArr);
                r.initBottleInfo(l[1], !!i);
                return r;
            }
            if (Number(s) ==ObstacleAllType.Candlebox) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: f = 2,
                        height: h = 2
                    },
                    SpecifyColor: g = SpecifyColor.any,
                    Hp: y = 8,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Candlebox,
                    name:ObstacleAllType1.CDE,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                (r = this.createMultiObstacleItem(e, t, c, i)).initCandleBox(l[1], !!i);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Candlebox,
                    name:ObstacleAllType1.CDE,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyObstacleItems(e, t, r, u);
                return r;
            }
            if (Number(s) ==ObstacleAllType.SafeBox) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 2,
                        height: 2
                    },
                    SpecifyColor: SpecifyColor.null,
                    Hp: l[1],
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.SafeBox,
                    name:ObstacleAllType1.SAF,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                r = this.createMultiObstacleItem(e, t, c, i);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.null,
                    Hp: -1,
                    LayoutType: c.LayoutType,
                    ObstacleAllType:ObstacleAllType.SafeBox,
                    name:ObstacleAllType1.SAF,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyObstacleItems(e, t, r, u);
                return r;
            }
            if (Number(s) ==ObstacleAllType.cupboard) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 2,
                        height: 2
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: l[1],
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.cupboard,
                    name:ObstacleAllType1.CBD,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                r = this.createMultiObstacleItem(e, t, c, i);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType: c.LayoutType,
                    ObstacleAllType:ObstacleAllType.oneCupboardPlate,
                    name:ObstacleAllType1.CBD,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyObstacleItems(e, t, r, u);
                return r;
            }
            if (Number(s) ==ObstacleAllType.BirdNest) {
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 2,
                        height: 2
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 5,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.BirdNest,
                    name:ObstacleAllType1.BNT,
                    aroundMatch: true,
                    createOther: true,
                    canMove: false
                };
                r = this.createMultiObstacleItem(e, t, c, i);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType: c.LayoutType,
                    ObstacleAllType:ObstacleAllType.BirdNest,
                    name:ObstacleAllType1.BNT,
                    aroundMatch: true,
                    createOther: true,
                    canMove: false
                };
                this.createEmptyObstacleItems(e, t, r, u);
                return r;
            }
            if (Number(s) ==ObstacleAllType.Icicle) {
                var p = l[2], d = l[1], h = p % 2 ? 1 : d, f = p % 2 ? d : 1;
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: Number(f),
                        height: Number(h)
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: d,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.Icicle,
                    name:ObstacleAllType1.ICI,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                n.log("创建冰柱，宽高", c.FloorArea, p);
                r = this.createMultiObstacleItem(e, t, c, i);
                if (i) {
                    r.initIcicle(p);
                    return r;
                }
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType: c.LayoutType,
                    ObstacleAllType:ObstacleAllType.Icicle,
                    name:ObstacleAllType1.ICI,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyPollars(e, t, r, u, p);
                r.initIcicle(p);
                return r;
            }
            if (Number(s) ==ObstacleAllType.curtain) {
                var g = Number(l[2]), y = Number(l[1]);
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: f = Number(l[3]),
                        height: h = Number(l[4])
                    },
                    SpecifyColor: g,
                    Hp: y,
                    LayoutType:LayerType.Top,
                    ObstacleAllType:ObstacleAllType.curtain,
                    name:ObstacleAllType1.CUR,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                r = this.createMultiObstacleItem(e, t, c, i);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.null,
                    Hp: -1,
                    LayoutType:LayerType.Top,
                    ObstacleAllType:ObstacleAllType.curtain,
                    name:ObstacleAllType1.CUR,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyObstacleItems(e, t, r, u);
                return r;
            }
            if (Number(s) ==ObstacleAllType.DrillFill) {
                g = Number(l[2]), y = Number(l[1]);
                var m = Number(l[3]);
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: f = 0 == m || 2 == m ? 1 : 2,
                        height: h = 0 == m || 2 == m ? 2 : 1
                    },
                    SpecifyColor: g,
                    Hp: y,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.DrillFill,
                    name:ObstacleAllType1.DRI,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                (r = this.createMultiObstacleItem(e, t, c, i)).initDrill(m);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: g,
                    Hp: y,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.DrillFill,
                    name:ObstacleAllType1.DRI,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyDrillItems(e, t, m, r, u);
                return r;
            }
            if (Number(s) ==ObstacleAllType.CupHolder) {
                n.log("");
                y = Number(l[1]);
                var v = l[2];
                c = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: -1,
                        height: -1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: y,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.CupHolder,
                    name:ObstacleAllType1.CHD,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                (r = this.createMultiObstacleItem(e, t, c, i)).initCupHolder(l[2]);
                if (i) return r;
                let u = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: -1,
                    LayoutType:LayerType.Middle,
                    ObstacleAllType:ObstacleAllType.CupHolder,
                    name:ObstacleAllType1.CHD,
                    aroundMatch: true,
                    createOther: false,
                    canMove: false
                };
                this.createEmptyCupHolderItems(v, r, u);
                return r;
            }
            n.log("障碍物初始化报错", a);
        }
    };
    public createSingleObstacleItem(e, t, a, o) {
        void 0 === o && (o = null);
        var i, r = {};
        l.deepClone(r, a);
        var n = this.obstacleItemPool.size() > 0 ? this.obstacleItemPool.get() : cc.instantiate(this.obstacleItem);
        n.getComponent(h) || n.addComponent(h);
        i = n.getComponent(h);
        if (!o) {
            this.setObstacleParent(e, t, r.LayoutType, i);
            i.init(e, t, r);
            return i;
        }
        n.parent = o;
        i.init(e, t, r);
        i.itemType ==ObstacleAllType.Honey && i.initEditorHoney();
        return i;
    };
    public setObstacleParent(e, t, a, o, i?, r?) {
        void 0 === i && (i = false);
        void 0 === r && (r = true);
        if (i) o.node.parent = this.multiAreaParent; else if (a ==LayerType.Lowest) {
            if (f._instance.bottomSquareGrid[e][t]) {
                n.log("lowest 该位置有方块了", e, t);
                if (!r) return;
                f._instance.recoverSquare(f._instance.bottomSquareGrid[e][t]);
            }
            this.lowestParent.addChild(o.node);
            f._instance.displayMapInfo[e][t] && (f._instance.bottomSquareGrid[e][t] = o);
        } else if (a ==LayerType.Middle) {
            if (b.middleSquareGrid[e][t]) {
                n.log("middle 该位置有方块了", e, t);
                if (!r) return;
                f._instance.recoverSquare(b.middleSquareGrid[e][t]);
            }
            f._instance.displayMapInfo[e][t] && b.setMiddleSquareGrid(e, t, o);
            this.middleParents.addChild(o.node);
        } else if (a ==LayerType.Top) {
            if (f._instance.topSquareGrid[e][t]) {
                n.log("top 该位置有方块了", e, t);
                if (!r) return;
                f._instance.recoverSquare(f._instance.topSquareGrid[e][t]);
            }
            f._instance.displayMapInfo[e][t] && (f._instance.topSquareGrid[e][t] = o);
            this.topParents.addChild(o.node);
        }
    };
    public createEmptyItem(e, t, a, o, i) {
        var r = {}, s = this.emptyObstaclePool.size() > 0 ? this.emptyObstaclePool.get() : cc.instantiate(this.emptyObstacleItem);
        s.getComponent(p) || s.addComponent(p);
        var c = s.getComponent(p);
        l.deepClone(r, o);
        c.init(e, t, a, r);
        a.emptyObstacleArr.push(c);
        c.obsIndex = i;
        i++;
        this.setObstacleParent(e, t, r.LayoutType, c, false, true);
        n.log("创建空的障碍物", r, e, t);
    };
    public createEmptyObstacleItems(e, t, a, o) {
        var i = a.itemInfo.FloorArea;
        a.emptyObstacleArr = [];
        for (var r = 0, l = 0; l < i.height; l++) for (var s = 0; s < i.width; s++) if (f._instance.displayMapInfo[e + s][t + l] == m.DisplayMapType.Normal) {
            this.createEmptyItem(e + s, t + l, a, o, r);
            r++;
        } else n.log("创建空的障碍物失败");
    };
    public createEmptyCupHolderItems(e, t, a) {
        for (var o = [], i = e.split("&"), r = 0; r < i.length; r++) {
            var l = i[r].split("~");
            o.push({
                row: Number(l[0]),
                col: Number(l[1])
            });
        }
        n.log("创建杯架空障碍物地点集合-----", o);
        var s = 0;
        for (r = 0; r < o.length; r++) {
            var c = o[r], u = c.row, p = c.col;
            if (f._instance.displayMapInfo[u] && f._instance.displayMapInfo[u][p] == m.DisplayMapType.Normal) {
                this.createEmptyItem(u, p, t, a, s);
                s++;
            } else n.log("床架杯架空报错", o[r]);
        }
    };
    public createEmptyDrillItems(e, t, a, o, i) {
        var r = [];
        r.push({
            row: e,
            col: t
        });
        switch (a) {
            case 0:
                r.push({
                    row: e,
                    col: t - 1
                });
                break;

            case 1:
                r.push({
                    row: e + 1,
                    col: t
                });
                break;

            case 2:
                r.push({
                    row: e,
                    col: t + 1
                });
                break;

            case 3:
                r.push({
                    row: e - 1,
                    col: t
                });
        }
        n.log("创建钻头空障碍物地点集合-----", r);
        for (var l = 0, s = 0; s < r.length; s++) {
            var c = r[s], u = c.row, p = c.col;
            if (f._instance.displayMapInfo[u] && f._instance.displayMapInfo[u][p] == m.DisplayMapType.Normal) {
                this.createEmptyItem(u, p, o, i, l);
                l++;
            } else n.log("创建钻头报错", r[s]);
        }
    };
    public createEmptyPollars(e, t, a, o, i) {
        var r = a.itemInfo.FloorArea;
        a.emptyObstacleArr = [];
        var l = 0;
        n.log("创建冰柱空", r, i, e, t);
        if (0 == i) for (var s = 0; s < r.height; s++) if (f._instance.displayMapInfo[e][t - s] == m.DisplayMapType.Normal) {
            this.createEmptyItem(e, t - s, a, o, l);
            l++;
        } else n.log("创建空的障碍物失败"); else if (1 == i) for (s = 0; s < r.width; s++) if (f._instance.displayMapInfo[e + s][t] == m.DisplayMapType.Normal) {
            this.createEmptyItem(e + s, t, a, o, l);
            l++;
        } else n.log("创建空的障碍物失败"); else if (2 == i) for (s = 0; s < r.height; s++) if (f._instance.displayMapInfo[e][t + s] == m.DisplayMapType.Normal) {
            this.createEmptyItem(e, t + s, a, o, l);
            l++;
        } else n.log("创建空的障碍物失败"); else if (3 == i) for (s = 0; s < r.width; s++) if (f._instance.displayMapInfo[e - s][t] == m.DisplayMapType.Normal) {
            this.createEmptyItem(e - s, t, a, o, l);
            l++;
        } else n.log("创建空的障碍物失败");
    };
    public destoryObstacleItem(e) {
        var t = this;
        if (e && e.parent) {
            var a, o = e.getComponent(h), l = e.getComponent(d);
            if (o) {
                var c = o._row, u = o._col;
                f._instance.topSquareGrid[c] && f._instance.topSquareGrid[c][u] && f._instance.topSquareGrid[c][u] == o ? f._instance.topSquareGrid[c][u] = null : b.middleSquareGrid[c] && b.middleSquareGrid[c][u] && b.middleSquareGrid[c][u] == o ? b.middleSquareGrid[c][u] = null : f._instance.bottomSquareGrid[c] && f._instance.bottomSquareGrid[c][u] && f._instance.bottomSquareGrid[c][u] == o && (f._instance.bottomSquareGrid[c][u] = null);
                a = o.itemInfo.ObstacleAllType;
                this.pushObstacleClearArr(a);
                o.destorySelf();
                n.log("障碍物回收1");
                this.obstacleItemPool.put(e);
                this.setAllHoneys();
                b.setGlobalScheduler(function () {
                    t.updateObstacleTargetCount(a);
                }, .1);
            } else if (l) {
                for (var p = l._row, g = l._col, y = l.itemInfo.name, m = 0; m < l.emptyObstacleArr.length; m++) {
                    var v = l.emptyObstacleArr[m];
                    c = v._row, u = v._col;
                    if (f._instance.topSquareGrid[c] && f._instance.topSquareGrid[c][u] && f._instance.topSquareGrid[c][u] == v) {
                        n.log("回收空障碍物-高", c, u);
                        f._instance.topSquareGrid[c][u] = null;
                    } else if (b.middleSquareGrid[c] && b.middleSquareGrid[c][u] && b.middleSquareGrid[c][u] == v) {
                        n.log("回收空障碍物-中", c, u);
                        b.middleSquareGrid[c][u] = null;
                    } else if (f._instance.bottomSquareGrid[c] && f._instance.bottomSquareGrid[c][u] && f._instance.bottomSquareGrid[c][u] == v) {
                        n.log("回收空障碍物-底", c, u);
                        f._instance.bottomSquareGrid[c][u] = null;
                    } else n.log("空障碍物回收报错~~~", b.middleSquareGrid);
                    n.log("多格障碍物站位块消除---");
                    this.emptyObstaclePool.put(v.node);
                }
                a = l.itemInfo.ObstacleAllType;
                this.pushObstacleClearArr(a);
                this.updateObstacleTargetCount(a);
                l.emptyObstacleArr = [];
                l.destorySelf();
                n.log("障碍物回收2");
                this.multiObstaclePool.put(e);
                y ==ObstacleAllType1.GLD && this.createGrass(p - 1, g - 1);
            }
            b.setGlobalScheduler(function () {
                i.trigger(r.ADD_ALL_FILL, {
                    callTime: s.getTimestamp(),
                    tTime: 0
                });
            });
        } else n.log("销毁障碍物报错", e);
    };
    public destoryObstacleItems(e) {
        var t = this;
        e.forEach( (e) => {
            t.destoryObstacleItem(e);
        });
    };
    public onClearObstacle(e,_) {
        e._row, e._col;
        e.onClear(null);
    };
    public clearMutilObstacle(e) {
        if (e.node.getComponent(d)) {
            for (var t = e._row, a = e._col, o = e.itemInfo.name, i = 0; i < e.emptyObstacleArr.length; i++) {
                var r = e.emptyObstacleArr[i], l = r._row, s = r._col;
                f._instance.topSquareGrid[l] && f._instance.topSquareGrid[l][s] && f._instance.topSquareGrid[l][s] == r ? f._instance.topSquareGrid[l][s] = null : b.middleSquareGrid[l] && b.middleSquareGrid[l][s] && b.middleSquareGrid[l][s] == r ? b.middleSquareGrid[l][s] = null : f._instance.bottomSquareGrid[l] && f._instance.bottomSquareGrid[l][s] && f._instance.bottomSquareGrid[l][s] == r ? f._instance.bottomSquareGrid[l][s] = null : n.log("空障碍物回收报错~~~", b.middleSquareGrid);
                n.log("多格障碍物站位块消除---");
                this.emptyObstaclePool.put(r.node);
            }
            e.emptyObstacleArr = [];
            f._instance.recoverSquare(e);
            o ==ObstacleAllType1.GLD && this.createGrass(t - 1, a - 1);
        } else n.log("清除多格障碍物报错---找不到item", e);
    };
    public clearEmptyObstacle(e, t) {
        if (-1 != t.emptyObstacleArr.indexOf(e)) {
            var a = e._row, o = e._col;
            t.emptyObstacleArr.splice(t.emptyObstacleArr.indexOf(e), 1);
            b.middleSquareGrid[a] && b.middleSquareGrid[a][o] && b.middleSquareGrid[a][o] == e && (b.middleSquareGrid[a][o] = null);
            this.emptyObstaclePool.put(e.node);
            i.trigger(r.ADD_ALL_FILL, {
                callTime: s.getTimestamp(),
                tTime: 0
            });
        } else n.log("删除空的障碍物报错");
    };
    public drillClearItems(e) {
        var t = [], a = [];
        e.forEach( (e) => {
            e.node && e.node.getComponent(h) ? a.push(e) : e.node && e.node.getComponent(p) && t.push(e);
        });
        t.length && this.onForceClearMulObstacles(t);
        a.length && this.onForceClearSingleObstacles(a);
    };
    public onForceClearMulObstacles(e) {
        e.forEach( (e) => {
            e.node && e.node.getComponent(p) && e.pointerObstacle.onEmptyForceClear();
        });
    };
    public onForceClearSingleObstacles(e) {
        e.forEach( (e) => {
            e.node && e.node.getComponent(h) && e.onForceClear();
        });
    };
    public getIsSameColor(e, t) {
        return !(!e || e.itemInfo.SpecifyColor != SpecifyColor.any) || (!e || e.itemInfo.SpecifyColor != SpecifyColor.null) && !(!e || !t || e.itemInfo.SpecifyColor != t.itemType);
    };
    public getPosIsEnmpty(e, t, a) {
        if (a ==LayerType.Lowest) {
            if (f._instance.bottomSquareGrid[e][t]) {
                n.log("bottom 该位置已经有了方块", e, t);
                return false;
            }
        } else if (a ==LayerType.Middle) {
            if (b.middleSquareGrid[e][t]) {
                n.log("middle 该位置已经有了方块", e, t, b.middleSquareGrid[e][t]);
                return false;
            }
        } else if (a ==LayerType.Top && f._instance.topSquareGrid[e][t]) {
            n.log(" top 该位置已经有了方块", e, t);
            return false;
        }
        return true;
    };
    public matchDestoryItems(e) {
        var t = this;
        if (e.length) {
            for (var a = this.getMultiObstacleArr(), o = 0; o < a.length; o++) if (!a[o].isClearAll) {
                var i = a[o].emptyObstacleArr;
                n.log("多格障碍物--", a[o].emptyObstacleArr.length);
                if (a[o].itemInfo.name ==ObstacleAllType1.CBO) {
                    for (var r = a[o], l = b.getNeighborPosWithMultiSquare({
                        row: r._row,
                        col: r._col
                    }, 2, 2), s = [], c = [], u = 0; u < e.length; u++) for (var p = 0; p < l.length; p++) e[u]._row == l[p].row && e[u]._col == l[p].col && c.push(e[u]);
                    for (var d = 0; d < r.colorBottleInfo.length; d++) for (var h = 0; h < c.length; h++) r.colorBottleInfo[d].color != SpecifyColor.any && c[h].itemType != r.colorBottleInfo[d].color || s.push(d);
                    n.log("棋子们合成,药水要消除的块---", s);
                    if (s.length > 0) {
                        r.clearBottleItems(s);
                        var f = a[o].itemInfo.ObstacleAllType;
                        this.updateObstacleTargetCount(f);
                    }
                } else if (a[o].itemInfo.name ==ObstacleAllType1.CDE) {
                    var g = a[o], y = (l = b.getNeighborPosWithMultiSquare({
                        row: g._row,
                        col: g._col
                    }, 2, 2), []);
                    n.log("蜡烛盒子", l, e);
                    for (u = 0; u < e.length; u++) for (p = 0; p < l.length; p++) e[u]._row == l[p].row && e[u]._col == l[p].col && y.push(e[u]);
                    n.log("棋子们合成,蜡烛盒子周围要消除的块---", y);
                    g.clearCandleBoxByNeighborArr(y);
                    f = a[o].itemInfo.ObstacleAllType;
                    this.updateObstacleTargetCount(f);
                } else {
                    for (var m = [], v = 0; v < i.length; v++) for (d = 0; d < e.length; d++) (P = this.matchDestoryOneItem(e[d], i[v])) && -1 == m.indexOf(P) && m.push(P);
                    if (m.length) {
                        n.log("多格子节点消除----", m.length);
                        a[o].onEmptyClear(m);
                    }
                }
            }
            var C = this.getAllSingleObstacleArr(), T = [];
            for (o = 0; o < C.length; o++) {
                var M = C[o];
                for (v = 0; v < e.length; v++) {
                    var P;
                    (P = this.matchDestoryOneItem(e[v], M)) && T.push(P);
                }
            }
            T.forEach( (e) => {
                t.onClearObstacle(e, true);
            });
        } else n.log("没有要合成消除的");
    };
    public createMultiObstacleItem(e, t, a, o) {
        void 0 === o && (o = null);
        var i, r = {};
        l.deepClone(r, a);
        var n = this.multiObstaclePool.size() > 0 ? this.multiObstaclePool.get() : cc.instantiate(this.multiObstacleItem);
        n.getComponent(d) || n.addComponent(d);
        if (!o) {
            i = n.getComponent(d);
            this.setObstacleParent(e, t, r.LayoutType, i, true);
            i.init(e, t, a);
            return i;
        }
        i = n.getComponent(d);
        n.parent = o;
        i.init(e, t, a);
        return i;
    };
    public matchDestoryOneItem(e, t) {
        var a = e._row, o = e._col, i = e.squareType;
        if (i == m.SquareType.MatchItem) {
            if (b.isHaveObstacleInHigherLayout(t)) return;
            if (!this.getIsSameColor(t, e)) return;
            if (t.itemInfo.LayoutType ==LayerType.Top && t.itemInfo.aroundMatch && b.getIsNeighbor(e, t)) return t;
            if (t.itemInfo.LayoutType ==LayerType.Middle && t.itemInfo.aroundMatch && b.getIsNeighbor(e, t)) return t;
            if (t.itemInfo.LayoutType ==LayerType.Lowest && t._col == o && t._row == a) return t;
        } else if (i == m.SquareType.PropItem) {
            if (t.itemInfo.SpecifyColor !== SpecifyColor.any) return;
            if (t.itemInfo.LayoutType ==LayerType.Top && t.itemInfo.aroundMatch && b.getIsNeighbor(e, t)) return t;
            if (t.itemInfo.LayoutType ==LayerType.Middle && t.itemInfo.aroundMatch && b.getIsNeighbor(e, t)) return t;
            if (t.itemInfo.LayoutType ==LayerType.Lowest && t._col == o && t._row == a) return t;
        } else n.log("棋子合成销毁，类型报错", i);
    };
    public clearAllObstacle() {
        var e = this;
        this.getAllSingleObstacleArr().forEach(function (t) {
            e.onClearObstacle(t, true);
        });
    };
    public onMatchClear(e) {
        var t = false, a = false;
        if (e.squareType == m.SquareType.MatchItem) for (var o = this.getMultiObstacleArr(), i = 0; i < o.length; i++) if (o[i].itemInfo.Hp > 0 && o[i].itemInfo.name ==ObstacleAllType1.CUR && e.itemType == o[i].itemInfo.SpecifyColor && !t) {
            o[i].clearCurtain(e);
            t = true;
        } else if (o[i].itemInfo.Hp > 0 && o[i].itemInfo.name ==ObstacleAllType1.DRI && e.itemType == o[i].itemInfo.SpecifyColor && !a) {
            o[i].clearOneDrill(e);
            a = true;
        }
    };
    public onClearMatchs(e) {
        if (e.length) {
            for (var t = 0; t < e.length; t++) this.onClearOneMatch(e[t].row, e[t].col);
            this.getMultiObstacleArr().forEach(function (t) {
                t.propMatchClear(e);
            });
        } else n.log("没有要消除的");
    };
    public onClearOneMatch(e, t) {
        f._instance.topSquareGrid[e] && f._instance.topSquareGrid[e][t] ? this.onClearObstacle(f._instance.topSquareGrid[e][t], false) : b.middleSquareGrid[e] && b.middleSquareGrid[e][t] && b.middleSquareGrid[e][t].squareType == m.SquareType.ObstacleItem ? this.onClearObstacle(b.middleSquareGrid[e][t], false) : f._instance.bottomSquareGrid[e] && f._instance.bottomSquareGrid[e][t] && this.onClearObstacle(f._instance.bottomSquareGrid[e][t], false);
    };
    public createFlower(e, t, a?) {
        var o = this;
        void 0 === a && (a = false);
        b.setGlobalScheduler(function () {
            for (var i = -1; i <= 1; i++) for (var r = -1; r <= 1; r++) if (f._instance.displayMapInfo[e + i] && f._instance.displayMapInfo[e + i][t + r] == m.DisplayMapType.Normal) {
                var n = b.middleSquareGrid[e + i][t + r];
                if (n && !n.canMove && !a) continue;
                var l = {
                    enable: true,
                    MoveStatus: false,
                    FloorArea: {
                        width: 1,
                        height: 1
                    },
                    SpecifyColor: SpecifyColor.any,
                    Hp: 1,
                    LayoutType:LayerType.Lowest,
                    ObstacleAllType:ObstacleAllType.PurpleFlower,
                    name:ObstacleAllType1.PFL,
                    aroundMatch: false,
                    createOther: false,
                    canMove: false
                };
                o.createSingleObstacleItem(e + i, t + r, l, null);
            }
            y.updateTarget();
        }, .1);
    };
    public initGemCount(e) {
        this.totalGemCount = e;
        this.createGemCount = 0;
        this.matchGemCount = 0;
    };
    public setMagicHatClear() {
        v.playMagicCloseAudio();
        this.getAllSingleObstacleArr().forEach( (e) => {
            e.itemInfo.name ==ObstacleAllType1.MHT && e.setMagicClose();
        });
    };
    public createGemMatchItem(e, t) {
        var a = this;
        n.log("创建宝石", this.totalGemCount, this.createGemCount);
        var o = 3;
        if (this.totalGemCount - this.createGemCount < 0) this.setMagicHatClear(); else {
            if (this.totalGemCount - this.createGemCount <= 3) {
                o = this.totalGemCount - this.createGemCount;
                this.setMagicHatClear();
            }
            v.playMagicWhooshAudio();
            for (var i = b.getRandomMatchPos(o), r = .1, l = 0; l < o; l++) (function (o) {
                if (i && i[o]) {
                    n.log("创建宝石==", i);
                    var l = i[o].row, s = i[o].col, u = (b.middleSquareGrid[l][s], c.playCreateGemAni({
                        row: e,
                        col: t
                    }, {
                        row: l,
                        col: s
                    }, function () {
                        var e = C.createMatchItem(l, s, m.MatchItemType.purpleGem);
                        e.setRowCol(l, s);
                        b.middleSquareGrid[l][s] && f._instance.recoverSquare(b.middleSquareGrid[l][s]);
                        b.middleSquareGrid[l][s] = e;
                        v.playMagicGemLandAudio();
                        b.checkCanFill() && b.AllFill();
                        b.checkIsCanEliminate() && b.startEliminate();
                    })), p = u.time;
                    u.spine;
                    a.createGemCount += 1;
                    r = Math.max(r, p);
                }
            })(l);
            b.setGlobalScheduler(function () {
                b.getMatchGuideData();
            }, r + .1);
        }
    };
    public createBirdMatchItem(e, t) {
        var a = this;
        n.log("创建小鸟障碍物");
        var o = b.getRandomMatchPosFromCol(3);
        n.log("创建小鸟障碍物arr==", o);
        o.sort(function (e, t) {
            return e.row - t.row;
        });
        for (var l = .1, u = 0; u < 3; u++) (function (i) {
            if (o && o[i]) {
                var r = o[i].row, n = o[i].col, s = c.playCreateBirdAni({
                    row: e,
                    col: t
                }, {
                    row: r,
                    col: n
                }, i, function () {
                    var e = {
                        enable: true,
                        MoveStatus: true,
                        FloorArea: {
                            width: 1,
                            height: 1
                        },
                        SpecifyColor: SpecifyColor.any,
                        Hp: -1,
                        LayoutType:LayerType.Middle,
                        ObstacleAllType:ObstacleAllType.Bird,
                        name:ObstacleAllType1.BID,
                        aroundMatch: false,
                        createOther: false,
                        canMove: true
                    }, t = f._instance.middleParents, o = a.createSingleObstacleItem(r, n, e, t);
                    o.setRowCol(r, n);
                    b.middleSquareGrid[r][n] && f._instance.recoverSquare(b.middleSquareGrid[r][n]);
                    b.middleSquareGrid[r][n] = o;
                    v.playBirdFall();
                }), u = s.time;
                s.spine;
                l = Math.max(l, u);
            }
        })(u);
        b.setGlobalScheduler(function () {
            i.trigger(r.ADD_ALL_FILL, {
                callTime: s.getTimestamp(),
                tTime: 0
            });
        }, l + .1);
    };
    public onGemMatch() {
        this.matchGemCount -= 1;
    };
    public createDiamondItem(e) {
        if (e && e.node) {
            var t = y.getSquareNumberType(m.SquareType.ObstacleItem), a = y.target_info;
            n.log("createDiamondItem==11==");
            for (var o = 0; o < a.length; o++) if (a[o].squareType == t && a[o].itemType ==ObstacleAllType.Rock) {
                n.log("createDiamondItem==22==");
                if (!e.node) continue;
                u.playDiamondFlyAni(e.node.position, g.instance.targetItems[o], function () { });
            }
        }
    };
    public setMailBoxClear() {
        var e = this.getAllSingleObstacleArr(), t = false;
        e.forEach( (e) => {
            if (e.itemInfo.name ==ObstacleAllType1.MAI) {
                e.setMailBoxClear();
                t = true;
            }
        });
        t && v.playMailBoxCloseAudio();
    };
    public createMailItem(e) {
        var t = this;
        if (e && e.node) {
            var a = y.getSquareNumberType(m.SquareType.ObstacleItem), o = y.target_info;
            n.log("可以创建邮件", e.node);
            for (var i = (i) => {
                if (o[i].squareType == a && o[i].itemType == ObstacleAllType.MailBox) {
                    n.log("可以创建邮件");
                    if (!e.node) return "continue";
                    v.playMailExitAudio();
                    r.updateObstacleTargetCount(ObstacleAllType.MailBox);
                    let d = e.node.position;
                    d.x = d.x - e.node.parent.width / 2 + 39;
                    d.y = d.y + e.node.height;
                    u.playMailMoveAni(d, g.instance.targetItems[i], () => {
                        t.upMailBoxStatus(o[i].tootalCount > 0);
                    });
                }
            }, r = this, l = 0; l < o.length; l++) i(l);
        }
    };
    public upMailBoxStatus(e) {
        e || this.setMailBoxClear();
    };
    public createGoldCoinFlyItem(e) {
        if (e && e.node) for (var t = y.getSquareNumberType(m.SquareType.ObstacleItem), a = y.target_info, o = function (o) {
            if (a[o].squareType == t && a[o].itemType == ObstacleAllType.GoldCoin) {
                v.playMailExitAudio();
                u.playGoldCoinMoveToTargetAni(e.node.position, g.instance.targetItems[o], function () {
                    i.trigger(r.FLY_ONE_TARGET, {
                        index: o
                    });
                });
            }
        }, n = 0; n < a.length; n++) o(n);
    };
    public isSameMulObstacle(e, t) {
        if (e.node && e.node.getComponent(p) && t.node && t.node.getComponent(p) && e.node.getComponent(p).pointerObstacle == t.node.getComponent(p).pointerObstacle) {
            n.log("两个空障碍物属于同一多格障碍物");
            return true;
        }
        return false;
    };
    public setAllHoneys() {
        for (var e = f._instance.topSquareGrid, t = 0; t < m.MAX_ROW; t++) if (e[t]) for (var a = 0; a < m.MAX_COL; a++) e[t][a] && e[t][a] && e[t][a].squareType == m.SquareType.ObstacleItem && e[t][a].itemType ==ObstacleAllType.Honey && this.getHoneyAnroundData(t, a);
    };
    public getHoneyAnroundData(e, t) {
        var a = [], o = [], i = f._instance.topSquareGrid;
        a.push(this.getIsHoney(e, t - 1));
        a.push(this.getIsHoney(e + 1, t));
        a.push(this.getIsHoney(e, t + 1));
        a.push(this.getIsHoney(e - 1, t));
        o.push(this.getIsHoney(e + 1, t - 1));
        o.push(this.getIsHoney(e + 1, t + 1));
        o.push(this.getIsHoney(e - 1, t + 1));
        o.push(this.getIsHoney(e - 1, t - 1));
        n.log("获取周围蜂蜜数据---", e, t, a, o);
        i[e] && i[e][t] && i[e][t].setHoney({
            direArr: a,
            angleArr: o
        });
    };
    public getIsHoney(e, t) {
        var a = f._instance.topSquareGrid;
        return a[e] && a[e][t] && a[e][t].squareType == m.SquareType.ObstacleItem && a[e][t].itemType ==ObstacleAllType.Honey ? 1 : 0;
    };
    public createGrass(e, t, a?, o?, i?) {
        void 0 === a && (a = 4);
        void 0 === o && (o = 4);
        void 0 === i && (i = false);
        n.log("创建草丛 4*4,左上角开始", e, t);
        if (a && o) for (var r = 0; r < a; r++) for (var l = 0; l > -o; l--) if (f._instance.displayMapInfo[e + r] && f._instance.displayMapInfo[e + r][t - l] == m.DisplayMapType.Normal) {
            var s = b.middleSquareGrid[e + r][t - l];
            if (s && !s.canMove && !i) continue;
            var c = {
                enable: true,
                MoveStatus: false,
                FloorArea: {
                    width: 1,
                    height: 1
                },
                SpecifyColor: SpecifyColor.any,
                Hp: 2,
                LayoutType:LayerType.Lowest,
                ObstacleAllType: ObstacleAllType.Grass,
                name:ObstacleAllType1.GRA,
                aroundMatch: false,
                createOther: false,
                canMove: false
            };
            this.createSingleObstacleItem(e + r, t - l, c, null);
        }
        y.updateTarget();
    };
    public getAllObstacleLeftCount() {
        for (var e = [], t = [], a = this.getAllSingleObstacleArr(), o = 0; o < a.length; o++) {
            var i = a[o];
            if (i.itemInfo.ObstacleAllType !=ObstacleAllType.curtain) b.isHaveObstacleInHigherLayout(i) || e.push(i); else {
                var r = i.itemInfo.SpecifyColor;
                -1 == t.indexOf(r) && t.push(r);
            }
        }
        n.log("getAllObstacleLeftCount singleArr======", e.length);
        n.log("getAllObstacleLeftCount curtainColorArr=====", t);
    };
    public getCurTainTargteColor() { };
    public getAllObstacleCanClearCount() { };
    public initAllObstacleClearCount() { };
    public addObstacleClearCount() { };
    public getObstaclePos() { };
    public getCanClearObstacleArr() {
        for (var e = [], t = this.getAllSingleObstacleArr(), a = 0; a < t.length; a++) {
            var o = t[a];
            !b.isHaveObstacleInHigherLayout(o) && o.itemInfo.enable && e.push(o);
        }
        n.log("找到所有没有被标记的障碍物集合", e);
        return e;
    };
    public markObstacle() { };
    public getMultiObstacleArr() {
        var e = [];
        this.multiAreaParent.children.forEach(function (t) {
            var a = t.getComponent(d);
            a && e.push(a);
        });
        return e;
    };
    public getEmptyObstacleArr() {
        for (var e = b.middleSquareGrid, t = f._instance.displayMapInfo, a = f._instance.bottomSquareGrid, o = f._instance.topSquareGrid, i = [], r = 0; r < m.MAX_ROW; r++) if (t[r]) for (var n = 0; n < m.MAX_COL; n++) if (t[r][n]) {
            o[r][n] && o[r][n].squareType == m.SquareType.ObstacleItem && o[r][n].node.getComponent(p) && i.push(o[r][n]);
            e[r][n] && e[r][n].squareType == m.SquareType.ObstacleItem && e[r][n].node.getComponent(p) && i.push(e[r][n]);
            a[r][n] && a[r][n].squareType == m.SquareType.ObstacleItem && a[r][n].node.getComponent(p) && i.push(a[r][n]);
        }
        return i;
    };
    public getSingleObstacleArr() {
        for (var e = b.middleSquareGrid, t = f._instance.displayMapInfo, a = f._instance.bottomSquareGrid, o = f._instance.topSquareGrid, i = [], r = 0; r < m.MAX_ROW; r++) if (t[r]) for (var n = 0; n < m.MAX_COL; n++) if (t[r][n]) {
            o[r][n] && o[r][n].squareType == m.SquareType.ObstacleItem && o[r][n].node.getComponent(h) && i.push(o[r][n]);
            e[r][n] && e[r][n].squareType == m.SquareType.ObstacleItem && e[r][n].node.getComponent(h) && i.push(e[r][n]);
            a[r][n] && a[r][n].squareType == m.SquareType.ObstacleItem && a[r][n].node.getComponent(h) && i.push(a[r][n]);
        }
        return i;
    };
    public getOneSingleObstacleArr(e) {
        for (var t = b.middleSquareGrid, a = f._instance.displayMapInfo, o = f._instance.bottomSquareGrid, i = f._instance.topSquareGrid, r = [], n = 0; n < m.MAX_ROW; n++) if (a[n]) for (var l = 0; l < m.MAX_COL; l++) a[n][l] && (i[n][l] && i[n][l].squareType == m.SquareType.ObstacleItem && i[n][l].node.getComponent(h) && i[n][l].node.getComponent(h).itemInfo.ObstacleAllType == e ? r.push(i[n][l]) : t[n][l] && t[n][l].squareType == m.SquareType.ObstacleItem && t[n][l].node.getComponent(h) && t[n][l].node.getComponent(h).itemInfo.ObstacleAllType == e ? r.push(t[n][l]) : o[n][l] && o[n][l].squareType == m.SquareType.ObstacleItem && o[n][l].node.getComponent(h) && o[n][l].node.getComponent(h).itemInfo.ObstacleAllType == e && r.push(o[n][l]));
        return r;
    };
    public getOneSingleObstacleTargetCount(e) {
        var t;
        t = e ==ObstacleAllType.Pearl ?ObstacleAllType.Oyster : e;
        var a = this.getOneSingleObstacleArr(t), o = 0;
        a.forEach( (e) => {
            e.node && (o += e.getTargetLeftCount());
        });
        return o;
    };
    public getOneSingleObstacleElimilateItem(e) {
        var t;
        t = e ==ObstacleAllType.Pearl ?ObstacleAllType.Oyster : e;
        var a = this.getOneSingleObstacleArr(t), o = [];
        a.forEach( (e) => {
            var t = e.getElimilateItem();
            t && t.length && (o = o.concat(t));
        });
        return Array.from(new Set(o));
    };
    public getOneMulObstacleArr(e) {
        var t = [];
        this.multiAreaParent.children.forEach(function (a) {
            var o = a.getComponent(d);
            o && o.itemInfo.ObstacleAllType == e && t.push(o);
        });
        return t;
    };
    public getOneMulObstacleElimilateItem(e) {
        var t = this.getOneMulObstacleArr(e), a = [];
        t.forEach( (e) => {
            var t = e.getAllElimilateItem();
            t && (a = a.concat(t));
        });
        return a;
    };
    public getOneMulObstacleTargetCount(e) {
        var t = this.getOneMulObstacleArr(e), a = 0;
        t.forEach( (e) => {
            a += e.getTargetLeftCount();
        });
        n.log("获取多格障碍物场景中所有合集", a, t);
        return a;
    };
    public getObstacleTargetByType(e) {
        return this.getIsMulObstacle(e) ? this.getOneMulObstacleElimilateItem(e) : this.getOneSingleObstacleElimilateItem(e);
    };
    public getObstacleCountInScene(e) {
        var t = 0;
        if (this.getIsMulObstacle(e)) t += this.getOneMulObstacleTargetCount(e); else {
            t += this.getOneSingleObstacleTargetCount(e);
            e ==ObstacleAllType.Bird && (t += this.getOneMulObstacleTargetCount(ObstacleAllType.BirdNest));
        }
        return t;
    };
    public getObstacleTargetCountByType(e, t) {
        n.log("通过类型获取所有障碍物", e);
        return _.getObstacleInfoByType(e).useFixedTarget ? Math.max(t.tootalCount, 0) : this.getIsMulObstacle(e) ? this.getOneMulObstacleTargetCount(e) : this.getOneSingleObstacleTargetCount(e);
    };
    public getIsMulObstacle(e) {
        return e ==ObstacleAllType.GrassLand || e ==ObstacleAllType.ColorBottle || e ==ObstacleAllType.cupboard || e ==ObstacleAllType.SafeBox || e ==ObstacleAllType.Icicle || e ==ObstacleAllType.Candlebox || e ==ObstacleAllType.CupHolder;
    };
    public getObstacleCanCreate(e) {
        return e ==ObstacleAllType.Grass && this.getObstacleCountInScene(ObstacleAllType.GrassLand) > 0 || e ==ObstacleAllType.PurpleFlower && this.getObstacleCountInScene(ObstacleAllType.Flowerpot) > 0;
    };
    public getAllTopSingleObstacleArr() {
        for (var e = b.middleSquareGrid, t = f._instance.displayMapInfo, a = f._instance.bottomSquareGrid, o = f._instance.topSquareGrid, i = [], r = 0; r < m.MAX_ROW; r++) if (t[r]) for (var n = 0; n < m.MAX_COL; n++) t[r][n] && (o[r][n] && o[r][n].node && o[r][n].squareType == m.SquareType.ObstacleItem && o[r][n].node.getComponent(h) ? i.push(o[r][n]) : e[r][n] && e[r][n].node && e[r][n].squareType == m.SquareType.ObstacleItem && (e[r][n].node.getComponent(h) || e[r][n].node.getComponent(p)) ? i.push(e[r][n]) : a[r][n] && a[r][n].node && a[r][n].squareType == m.SquareType.ObstacleItem && a[r][n].node.getComponent(h) && i.push(a[r][n]));
        return i;
    };
    public getAllSingleObstacleArr() {
        return this.getAllTopSingleObstacleArr();
    };
    public getMaxCountObstacleRow() { };
    public getMaxCountObstacleCol() { };
    public getMaxCountObstacleArea(e, t) {
        void 0 === e && (e = 3);
        void 0 === t && (t = 3);
    };
    public getOneObstacleTargetLeftCount() { };
    public updateObstacleTargetCount(e) {
        if (_.getObstacleInfoByType(e).useFixedTarget) y.updateOneTargetCount(m.SquareType.ObstacleItem, e); else {
            var t;
            t = this.getIsMulObstacle(e) ? this.getOneMulObstacleTargetCount(e) : this.getOneSingleObstacleTargetCount(e);
            y.updateOneTargetCount(m.SquareType.ObstacleItem, e, t);
        }
    };
}


export default ObstacleCtrl.getInstance();